#include <stdio.h>
#include <stdlib.h>

#define MAX 10000

int f[MAX+1];
int r[MAX+1];
int n;

int init()
{
    int i;
    for (i = 1; i <= MAX; i++) {
        f[i] = i;
        r[i] = 0;
    }
    n = 0;

    return 0;
}

int find(int n)
{
    if (n == f[n]) {
        return n;
    }

    f[n] = find(f[n]);
    return f[n];
}

int merge(int x, int y)
{
    int a = find(x);
    int b = find(y);

    if (a == b) {
        return 0;
    } else {
        f[b] = a;
        r[x] = r[y] = 1;
        return 1;
    }
}

int check()
{
    int i, flg, t;

    // check is a tree or not
    flg = 1; t = 0;
    for (i = 1; i <= n; i++) {
        f[i] = find(i);
        if (r[i]) {
            if (t != 0 && f[i] != t) {
                flg = 0; break;
            }
            t = f[i];
        }
    }
    return flg;
}

int main (int argc, char const* argv[])
{
    int a, b, testcase, flg, t;
    testcase = 1; flg = 1;
    init();

    while (scanf("%d %d", &a, &b) != EOF && a != -1) {
        if (0 == a && a == b) {
            if (check() && flg) {
                printf("Case %d is a tree.\n", testcase);
            } else {
                printf("Case %d is not a tree.\n", testcase);
            }
            init();
            flg = 1;
            testcase++;
        } else {
            n = a > n ? a : n;
            n = b > n ? b : n;
            t = merge(a, b);
            if (flg) {
                flg = t;
            }
        }
    }

    return 0;
}
